﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class HocVien_frmBaiThi : System.Web.UI.Page
{
    clsQtDeThi qtdt = new clsQtDeThi();
    clsBaiThi bt = new clsBaiThi();
    clsChiTietBT ctbt = new clsChiTietBT();
    clsKetQuaBaithi kqbt = new clsKetQuaBaithi();
    public double seconds;
    protected void Page_Load(object sender, EventArgs e)
    {

                
        if (!IsPostBack)
        {
            
            lblMathisinh.Text = Session["TenDangNhap"].ToString();
            lblNgayGio.Text = DateTime.Now.ToShortDateString();
            lblMaDT.Text = Request.QueryString["madethi"];
            lblmabt.Text = lblMathisinh.Text + lblMaDT.Text;
            seconds = 185;
            //seconds = qtdt.thoigian(lblMaDT.Text);
            getdata();
        }
    }
    public void getdata()
    {
        List<clsBaiThi> l = new List<clsBaiThi>();
        l = bt.getdata(lblMaDT.Text);
        DataList1.DataSource = l;
        DataList1.DataBind();

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string mach = string.Empty;
        string traloi = string.Empty;
        string mabt=lblmabt.Text;

        string madt = lblMaDT.Text;
        string ngaythi = lblNgayGio.Text;
        string tenbt = lblTenBaiThi.Text;
        string masv = lblMathisinh.Text;

        kqbt.ThemBaiThi(madt, mabt, ngaythi, tenbt, masv);
        foreach (DataListItem item in DataList1.Items)
        {

            string lblmach = ((Label)item.FindControl("lblMaCH")).Text;
            //mach = lblmach.Text;
            mach = lblmach;
            RadioButton rd2 = item.FindControl("RadioButton5") as RadioButton;
            //rd2.Checked = false;
            RadioButton rd3 = item.FindControl("RadioButton6") as RadioButton;
            //rd3.Checked = false;
            RadioButton rd4 = item.FindControl("RadioButton7") as RadioButton;
            //rd4.Checked = false;
            RadioButton rd5 = item.FindControl("RadioButton8") as RadioButton;

            List<RadioButton> rd = new List<RadioButton>();
            rd.Add(rd2);
            rd.Add(rd3);
            rd.Add(rd4);
            rd.Add(rd5);
            foreach (var rdb in rd)
            {
                if (rdb.Checked == true)
                {
                    traloi = rdb.Text;
                    break;
                }
                else
                {
                    traloi = "null";
                }
            }

            ctbt.CapnhatCTBT(mabt, mach, traloi);

        }
        kqbt.KetQua(mabt, madt);

        string url = "";
        url = "frmKetQuaThi.aspx?mabaithi=" + lblmabt.Text;
        Response.Redirect(url);

        //Response.Redirect("frmKetQuaThi.aspx");
       
    }
}
